
#include "GameEnemy.h"
#include "CreatureManager.h"



GameEnemyEntity::GameEnemyEntity()
:	mEnemyBase( F_NULL ) , mEnemy( F_NULL )
{
	mType = GCTENEMY;
}


GameEnemyEntity::~GameEnemyEntity()
{

}


fint32			GameEnemyEntity::GetExp()
{
	return mEnemy->intValue[ GEIV_EXP ];
}

fvoid			GameEnemyEntity::Init( GameEnemy* enemy )
{
	mData.Level = 0;// MathBase::GetRandomInt( enemy->intValue[ GEIV_LEVELMIN ] , enemy->intValue[ GEIV_LEVELMAX ] );

	GameEnemyBase* base = gCreatureManager->GetEnemyBase( enemy->intValue[ GEIV_BASEID ] );

	mEnemyBase = base;
	mEnemy = enemy;

	mEnemy->intValue[ GEIV_EXP ] = mData.Level * mData.Level / 2;

	fint32 temp[ 4 ];
	MEMCPY( temp , base->intValue + GEBIV_BASEVITALITY , 4 * sizeof( int ) );

	temp[0] += 0;//MathBase::GetRandomInt( 0 , 5 ) - 2;
	temp[1] += 0;//MathBase::GetRandomInt( 0 , 5 ) - 2;
	temp[2] += 0;//MathBase::GetRandomInt( 0 , 5 ) - 2;
	temp[3] += 0;//MathBase::GetRandomInt( 0 , 5 ) - 2;

	for ( int i = 0 ; i < 10 ; ++i )
	{
		int n = 0;//MathBase::GetRandomInt( 0 , 4 );

		switch (n)
		{
		case 0:
			temp[0]++;
			break;
		case 1:
			temp[1]++;
			break;
		case 2:
			temp[2]++;
			break;
		case 3:
			temp[3]++;
			break;
		}
	}

	fint32 max = temp[0] + temp[1] + temp[2] + temp[3];

	mData.ActionID = base->intValue[ GEBIV_ROLE ];
	mData.Vitality = (fint16)( ( ( mData.Level - 1 ) * base->levelUpPoint + base->intValue[ GEBIV_INITNUM ] ) * temp[0] / max );
	mData.Strength = (fint16)( ( ( mData.Level - 1 ) * base->levelUpPoint + base->intValue[ GEBIV_INITNUM ] ) * temp[1] / max );
	mData.Toughness = (fint16)( ( ( mData.Level - 1 ) * base->levelUpPoint + base->intValue[ GEBIV_INITNUM ] ) * temp[2] / max );
	mData.Dexterity = (fint16)( ( ( mData.Level - 1 ) * base->levelUpPoint + base->intValue[ GEBIV_INITNUM ] ) * temp[3] / max );

	InitBaseData();
	UpdateFightData();

	mFightData.Base.Charm = 100;

	mFightData.Base.HP = mFightData.Base.MAXHP;
	mFightData.Base.MP = mFightData.Base.MAXMP;

	mData.EXP = 0;

	mFightStatus.Fall = F_FALSE;
	mFightStatus.Status = SAST_NONE;
}

fvoid			GameEnemyEntity::Release()
{
	GameCreature::Release();

	mEnemyBase = F_NULL;
	mEnemy = F_NULL;
}

